export class CustomError extends Error {
  constructor(
    public statusCode: number,
    public code: string,
    public message: string,
    public details?: any
  ) {
    super(message)
    this.name = this.constructor.name
    Error.captureStackTrace(this, this.constructor)
  }
}

export class ValidationError extends CustomError {
  constructor(message: string, details?: any) {
    super(400, 'VALIDATION_ERROR', message, details)
  }
}

export class AuthenticationError extends CustomError {
  constructor(message: string = '认证失败') {
    super(401, 'AUTHENTICATION_ERROR', message)
  }
}

export class AuthorizationError extends CustomError {
  constructor(message: string = '权限不足') {
    super(403, 'AUTHORIZATION_ERROR', message)
  }
}

export class NotFoundError extends CustomError {
  constructor(message: string = '资源未找到') {
    super(404, 'NOT_FOUND_ERROR', message)
  }
}

export class DatabaseError extends CustomError {
  constructor(message: string = '数据库操作失败', details?: any) {
    super(500, 'DATABASE_ERROR', message, details)
  }
}
